function calc24 () {
  let expression = [].slice.call(arguments).sort()
  let operator = ['+', '-', '*', '/']
  let result = []
  let hash = {}
  !(function calc24Step (expression) {
    let len = expression.length
    let group_str = expression.slice(0).sort().toString()
    if (!hash[group_str]) {
      hash[group_str] = true
      if (len > 1) {
        for (let i = 0; i < len - 1; i++) {
          for (let j = i + 1; j < len; j++) {
            let sort_expression = expression.slice(0)
            let exp1 = sort_expression.splice(j, 1)[0]
            let exp2 = sort_expression.splice(i, 1)[0]
            for (let n = 0; n < 4; n++) {
              let new_expression = sort_expression.slice(0)
              new_expression.splice(0, 0, n > 1 || len == 2 ? exp1 + operator[n] + exp2 : '(' + exp1 + operator[n] + exp2 + ')')
              calc24Step(new_expression)
              if (exp1 != exp2 && n % 2) {
                new_expression.splice(0, 1, n > 1 || len == 2 ? exp2 + operator[n] + exp1 : '(' + exp2 + operator[n] + exp1 + ')')
                calc24Step(new_expression)
              }
            }
          }
        }
      } else if (Math.abs(eval(expression[0]) - 24) < 1e-6) {
        result.push(expression[0])
      }
    }
  })(expression)
  return result
}
export default calc24
